import type { ReactText } from 'react';
import type { FormInstance } from 'antd/es/form';
import type { SortProps, ScreenProp, IFormListData } from '@/services/listTable';

export interface ComponentsProp {
  state: ListTableType;
  tableForm: FormInstance;
  query: Record<string, any>;
  sign?: number;
  OperationPromptModal?: (callBack: () => void) => void;
  queryFormList?: (search?: string, isPageFirst?: boolean, isFilter?: boolean) => void;
}
interface TableParamsProp {
  page?: number;
  pageSize?: number;
  sort?: SortProps[];
}

export interface IRequestBasicParameters {
  pov: Record<string, any>;
  elementName: string;
  path?: string;
  folderId?: string;
  search?: string;
  screen: ScreenProp[];
}

export interface ListTableType {
  editedCol: string; // 编辑行key标识
  tableParameters: TableParamsProp; // table 分页 排序等参数
  screen: ScreenProp[]; // 筛选区域查询条件
  addFlag: boolean; // 当前是否处于添加行未保存状态
  tableLoading: boolean; // 查询时下需要加载数据，默认为 true
  filterIcon: boolean; // 标识是否用筛选框中条件进行查询过数据（是否显示筛选框上的小图标）默认 false
  selectedKey: ReactText[]; // 批量勾选数据key的集合
  listConfigData?: IFormListData; // 接口返回数格式
  isFirst?: boolean; // 首次加载标识
  saveState?: boolean; // 保存操作时状态
  // 权限状态
  permissionState?: 1 | 2 | 3 | 4 | 'NoAccess' | 'error'; // 1：使用权限，2：使用编辑权限，3：全部权限，4：所有者权限,  null:无权限-NoAccess
  styleObj?: { columnStyleObj: object }; // 列样式字段
  // 查数基本参数
  requestBasicParameters?: IRequestBasicParameters;
}

export type ListTableActionType =
  | {
      type: 'init';
      listConfigData: IFormListData;
      isFirst?: boolean;
      tableParameters?: TableParamsProp;
      saveState?: boolean;
      requestBasicParameters?: IRequestBasicParameters;
    }
  | {
      type: 'setAddFlag'; // 是否允许新增行
      addFlag: boolean;
    }
  | {
      type: 'setEditedCol';
      editedCol?: string;
      [key: string]: unknown;
    }
  | {
      type: 'setSelectedKey';
      selectedKey: ReactText[];
    }
  | {
      type: 'setFilterIcon';
      filterIcon: boolean;
    }
  | {
      type: 'setTableLoading';
    }
  | {
      type: 'setKeyAndValue';
      [key: string]: unknown;
    };
